package com.heima.kafka.listener;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojos.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @author ZQH
 * @version 1.0
 * @date 2023/8/27 17:47
 */
@Component
@Slf4j
public class HelloListener {

    @KafkaListener(topics = "user-topic")
    public void onMessage(String message){
        if (!StringUtils.isEmpty(message)){
            User user = JSON.parseObject(message, User.class);
            log.info("成功消费到kafka消息:{}",user);
        }

    }

}
